#!/bin/bash
category="GPU"

runlog="/tmp/gpu-run.log"

resultcode=0
resultmsg=""   # Perf: GE ${minGflops} Gflops

start_time=$(date +%s)

echo "FD测试程序开始..." > $runlog

# 启动 gpu_burn 命令并将输出重定向到 burn.log
cd /root/FD/629-24287-XXXX-FLD-42658
# nvidia-smi -pm 1 >> $runlog
./fieldiag.sh --no_bmc --level2 >> $runlog

fdlogFile=fieldiag.log

# 判断测试结果
result=$(grep "Final Result:" "$fdlogFile" | awk '{print $3}')

# 判断结果
if [ "$result" = "PASS" ]; then
    echo "测试通过：PASS" >> $runlog
elif [ "$result" = "FAIL" ]; then
    echo "测试失败：FAIL" >> $runlog
	resultcode=1
else
    echo "未知结果: $result" >> $runlog
	resultcode=2
fi
resultmsg=$result

end_time=$(date +%s)

run_time=$((end_time - start_time))

echo "FD测试，执行完成，执行时间：${run_time}秒" >> $runlog


# echo "category=${category};resultcode=${resultcode};resultmsg=${resultmsg};runtime=${run_time}"

# for ((i=1;i<=gpu_count;i++));do
#     model=$(nvidia-smi -i $((i-1)) --query-gpu=name --format=csv,noheader)
#     echo "category=${category};resultcode=${resultcode};resultmsg=${resultmsg};runtime=${run_time};model=${model}"
# done

echo "category=GPU;resultcode=${resultcode};resultmsg=${resultmsg};runtime=${run_time}"



exit 0


